package cate.common.table.mall.sheet;

import cate.common.table.ESheet;
import cate.common.table.d.GDMall;
import cate.common.table.mall.row.MallItemsRow;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@NoteClass(value = "商城商品")
public class MallItemsSheet extends ESheet<MallItemsRow> {

    @Override
    public String getSheetName() {
        return "商品";
    }

    @NoteField(value = "商店商品", detail = "Map<商店ID，普通商品列表>")
    private Map<Integer, List<MallItemsRow>> mallItemsMap;

    @Override
    protected void onLoaded() {
        mallItemsMap = new HashMap<>();
        for (MallItemsRow row : super.list) {
            if (row.type != GDMall.ItemType.T0) {
                continue;
            }
            List<MallItemsRow> list = mallItemsMap.computeIfAbsent(row.mallId, k -> new ArrayList<>());
            list.add(row);
        }
    }

    /** 获取一个商店的普通商品列表 */
    public List<MallItemsRow> getMallItemList(int mallId) {
        List<MallItemsRow> data = mallItemsMap.get(mallId);
        if (data == null) {
            return new ArrayList<>();
        }
        return data;
    }

    /** 获取一个商店某一个类型的商品 */
    public List<MallItemsRow> getMallItemList(int mallId, byte type) {
        List<MallItemsRow> result = new ArrayList<>();
        for (MallItemsRow row : super.list) {
            if (row.mallId == mallId && row.type == type) {
                result.add(row);
            }
        }
        return result;
    }
}
